package com.apes.fa.model;


import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.FaCategory;
import com.apes.scm.masterdata.product.model.FaDepreciationMethod;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;


/**
 * @description: 资产卡片导入
 * @author: cxm
 * @create: 2022-02-14 17:11
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = FaCardImportItem.CONST_TABLE_NAME)
public class FaCardImportItem extends BaseModel {

    public static final String CONST_TABLE_NAME = "fa_card_imp_item";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "资产卡片", padding = 32)
    @Comment("资产卡片编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fa_card_imp_id", referencedColumnName = "id")
    @Comment("资产批量导入")
    private FaCardImport faCardImport;

    @Column(name = "fa_id")
    @Comment("固定资产编码")//同资产卡片编码
    private String faId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fa_category_id", referencedColumnName = "id")
    @Comment("固定资产分类编码")
    private FaCategory faCategory;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("部门")
    private Dept dept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品名称")
    private Product product;

    @Column(name = "purchase_date")
    @Comment("购置日期")
    private Date purchaseDate;

    @Column(name = "original_value")
    @Comment("原值")
    private Double originalValue;

    @Column(name = "depreciation")
    @Comment("折旧")
    private Double depreciation;

    @Column(name = "enable_date")
    @Comment("启用日期")
    private Date enableDate;

    @Column(name = "use_year")
    @Comment("使用年限")
    private Integer useYear;

    @Column(name = "use_month")
    @Comment("使用月限")
    private Integer useMonth;

    @ManyToOne
    @JoinColumn(name = "depreciation_method_id",referencedColumnName = "id")
    @Comment("折旧方法")
    private FaDepreciationMethod depreciationMethod;

    @Column(name = "annual_depreciation_rate")
    @Comment("年折旧率")
    private Double annualDepreciationRate;

    @Column(name = "monthly_depreciation_rate")
    @Comment("月折旧率")
    private Double monthlyDepreciationRate;

    @Column(name = "fa_status")
    @Comment("资产状态")
    @States(name = "资产状态", values = {
            @State(id = "1", name = "在用"),
            @State(id = "2", name = "闲置"),
            @State(id = "3", name = "维修"),
            @State(id = "4", name = "借出"),
            @State(id = "5", name = "报废"),
            @State(id = "6", name = "售出"),
            @State(id = "7", name = "盘亏待处理"),
            @State(id = "8", name = "盘亏")
    })
    //资产状态(1:在用;2:闲置;3:维修;4:借出;5:报废;6:调拨售出;7:盘亏待处理;8:盘亏)
    private String faStatus;

    @Column(name = "fa_type")
    @Comment("资产类型")
    private String faType;

    @Column(name = "measurement_unit")
    @Comment("计量单位")
    private String measurementUnit;

    @Column(name = "remaining_depreciation_month")
    @Comment("剩余折旧月")
    private Integer remainingDepreciationMonth;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "responsible_person_id", referencedColumnName = "id")
    @Comment("负责人")
    private PartyRole responsiblePerson;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "custodian_id", referencedColumnName = "id")
    @Comment("保管人")
    private PartyRole custodian;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    @Comment("使用人")
    private PartyRole user;

    @Column(name = "accounting_mark")
    @Comment("记账标记")
    private boolean accountingMark;


}
